package com.j2eefast.flowable.bpm.service;


import cn.hutool.core.util.IdUtil;
import com.j2eefast.flowable.bpm.entity.bpmCrmPurchaseEntity;
import com.j2eefast.flowable.bpm.mapper.bpmCrmPurchaseMapper;
import com.j2eefast.common.core.mutidatasource.annotaion.DataSource;
import com.j2eefast.common.core.page.Query;
import com.j2eefast.common.core.utils.PageUtil;
import com.j2eefast.common.core.utils.ToolUtil;
import com.j2eefast.framework.utils.Constant;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
import java.util.Arrays;
/**
 *
 * 采购订单Service接口
 * @author: yhli
 * @date 2020-06-28 13:40
 */
@Service
public class bpmCrmPurchaseService extends ServiceImpl<bpmCrmPurchaseMapper,bpmCrmPurchaseEntity> {

	@Resource
	private bpmCrmPurchaseMapper bpmCrmPurchaseMapper;

	/**
	 * mybaitis-plus 页面分页查询
     */
    @DataSource(name="FLOWABLE")
	public PageUtil findPage(Map<String, Object> params) {
        QueryWrapper<bpmCrmPurchaseEntity> queryWrapper = new QueryWrapper<bpmCrmPurchaseEntity>();
              String saleCode = (String) params.get("saleCode");
         queryWrapper.eq(ToolUtil.isNotEmpty(saleCode), "sale_code", saleCode);
                               String saleUserid = (String) params.get("saleUserid");
         queryWrapper.eq(ToolUtil.isNotEmpty(saleUserid), "sale_userid", saleUserid);
          String saleOrderNumber = (String) params.get("saleOrderNumber");
         queryWrapper.eq(ToolUtil.isNotEmpty(saleOrderNumber), "sale_order_number", saleOrderNumber);
          String orderContractPrice = (String) params.get("orderContractPrice");
         queryWrapper.eq(ToolUtil.isNotEmpty(orderContractPrice), "order_contract_price", orderContractPrice);
          String orderIsTax = (String) params.get("orderIsTax");
         queryWrapper.eq(ToolUtil.isNotEmpty(orderIsTax), "order_is_tax", orderIsTax);
          String orderIsTransport = (String) params.get("orderIsTransport");
         queryWrapper.eq(ToolUtil.isNotEmpty(orderIsTransport), "order_is_transport", orderIsTransport);
          String orderIsGuarantee = (String) params.get("orderIsGuarantee");
         queryWrapper.eq(ToolUtil.isNotEmpty(orderIsGuarantee), "order_is_guarantee", orderIsGuarantee);
          String orderOtherItem = (String) params.get("orderOtherItem");
         queryWrapper.eq(ToolUtil.isNotEmpty(orderOtherItem), "order_other_item", orderOtherItem);
          String carVin = (String) params.get("carVin");
         queryWrapper.eq(ToolUtil.isNotEmpty(carVin), "car_vin", carVin);
          String carVehicle = (String) params.get("carVehicle");
         queryWrapper.eq(ToolUtil.isNotEmpty(carVehicle), "car_vehicle", carVehicle);
          String carMileage = (String) params.get("carMileage");
         queryWrapper.eq(ToolUtil.isNotEmpty(carMileage), "car_mileage", carMileage);
          String carTranmission = (String) params.get("carTranmission");
         queryWrapper.eq(ToolUtil.isNotEmpty(carTranmission), "car_tranmission", carTranmission);
          String carDrivertrain = (String) params.get("carDrivertrain");
         queryWrapper.eq(ToolUtil.isNotEmpty(carDrivertrain), "car_drivertrain", carDrivertrain);
          String carStatus = (String) params.get("carStatus");
         queryWrapper.eq(ToolUtil.isNotEmpty(carStatus), "car_status", carStatus);
             String channelPurchaseSource = (String) params.get("channelPurchaseSource");
         queryWrapper.eq(ToolUtil.isNotEmpty(channelPurchaseSource), "channel_purchase_source", channelPurchaseSource);
          String channelIsOpenSale = (String) params.get("channelIsOpenSale");
         queryWrapper.eq(ToolUtil.isNotEmpty(channelIsOpenSale), "channel_is_open_sale", channelIsOpenSale);
          String channelAuction = (String) params.get("channelAuction");
         queryWrapper.eq(ToolUtil.isNotEmpty(channelAuction), "channel_auction", channelAuction);
          String channelAuctionType = (String) params.get("channelAuctionType");
         queryWrapper.eq(ToolUtil.isNotEmpty(channelAuctionType), "channel_auction_type", channelAuctionType);
          String channelAuctionTimeType = (String) params.get("channelAuctionTimeType");
         queryWrapper.eq(ToolUtil.isNotEmpty(channelAuctionTimeType), "channel_auction_time_type", channelAuctionTimeType);
          String channelAuctionTime = (String) params.get("channelAuctionTime");
         queryWrapper.eq(ToolUtil.isNotEmpty(channelAuctionTime), "channel_auction_time", channelAuctionTime);
          String channelSellerName = (String) params.get("channelSellerName");
        queryWrapper.like(ToolUtil.isNotEmpty(channelSellerName), "channel_seller_name", channelSellerName);
          String channelSellerContactinfo = (String) params.get("channelSellerContactinfo");
         queryWrapper.eq(ToolUtil.isNotEmpty(channelSellerContactinfo), "channel_seller_contactinfo", channelSellerContactinfo);
             String managerPurchaseSpecialist = (String) params.get("managerPurchaseSpecialist");
         queryWrapper.eq(ToolUtil.isNotEmpty(managerPurchaseSpecialist), "manager_purchase_specialist", managerPurchaseSpecialist);
          String managerReview = (String) params.get("managerReview");
         queryWrapper.eq(ToolUtil.isNotEmpty(managerReview), "manager_review", managerReview);
             String managerIsPurchase = (String) params.get("managerIsPurchase");
         queryWrapper.eq(ToolUtil.isNotEmpty(managerIsPurchase), "manager_is_purchase", managerIsPurchase);
          String purchaseResult = (String) params.get("purchaseResult");
         queryWrapper.eq(ToolUtil.isNotEmpty(purchaseResult), "purchase_result", purchaseResult);
          String purchaseResultTime = (String) params.get("purchaseResultTime");
         queryWrapper.eq(ToolUtil.isNotEmpty(purchaseResultTime), "purchase_result_time", purchaseResultTime);
             String isWarehousing = (String) params.get("isWarehousing");
         queryWrapper.eq(ToolUtil.isNotEmpty(isWarehousing), "is_warehousing", isWarehousing);
          String cashierPaySentTime = (String) params.get("cashierPaySentTime");
         queryWrapper.eq(ToolUtil.isNotEmpty(cashierPaySentTime), "cashier_pay_sent_time", cashierPaySentTime);
          String cashierPayMethod = (String) params.get("cashierPayMethod");
         queryWrapper.eq(ToolUtil.isNotEmpty(cashierPayMethod), "cashier_pay_method", cashierPayMethod);
          String cashierProofFilepath = (String) params.get("cashierProofFilepath");
         queryWrapper.eq(ToolUtil.isNotEmpty(cashierProofFilepath), "cashier_proof_filepath", cashierProofFilepath);
          String cashierReceiptNumber = (String) params.get("cashierReceiptNumber");
         queryWrapper.eq(ToolUtil.isNotEmpty(cashierReceiptNumber), "cashier_receipt_number", cashierReceiptNumber);
             String confirmPayMethod = (String) params.get("confirmPayMethod");
         queryWrapper.eq(ToolUtil.isNotEmpty(confirmPayMethod), "confirm_pay_method", confirmPayMethod);
          String confirmPayAmount = (String) params.get("confirmPayAmount");
         queryWrapper.eq(ToolUtil.isNotEmpty(confirmPayAmount), "confirm_pay_amount", confirmPayAmount);
             String purchasePaySum = (String) params.get("purchasePaySum");
         queryWrapper.eq(ToolUtil.isNotEmpty(purchasePaySum), "purchase_pay_sum", purchasePaySum);
     		Page<bpmCrmPurchaseEntity> page = bpmCrmPurchaseMapper.selectPage(new Query<bpmCrmPurchaseEntity>(params).getPage(), queryWrapper);
		return new PageUtil(page);
    }

    /**
     * 自定义分页查询，含关联实体对像
     */
    @DataSource(name="FLOWABLE")
	public PageUtil findPage(Map<String, Object> params,bpmCrmPurchaseEntity bpmCrmPurchaseEntity) {
		Page<bpmCrmPurchaseEntity> page = bpmCrmPurchaseMapper.findPage(new Query<bpmCrmPurchaseEntity>(params).getPage(), bpmCrmPurchaseEntity,(String) params.get(Constant.SQL_FILTER))  ;
		return new PageUtil(page);
	}
	/**
     * 批量删除
     */
    @DataSource(name="FLOWABLE")
	@Transactional(rollbackFor = Exception.class)
	public boolean deletebpmCrmPurchaseByIds(String[] ids) {
		return removeByIds(Arrays.asList(ids));
	}

	/**
     * 单个删除
     */
    @DataSource(name="FLOWABLE")
	public boolean deletebpmCrmPurchaseById(String id) {
		return removeById(id);
	}

	/**
     * 保存
     */
    @DataSource(name="FLOWABLE")
	public boolean savebpmCrmPurchase(bpmCrmPurchaseEntity bpmCrmPurchase){
        bpmCrmPurchase.setId(IdUtil.fastSimpleUUID());
        return save(bpmCrmPurchase);
    }

	/**
     * 修改根居ID
     */
    @DataSource(name="FLOWABLE")
	public boolean updatebpmCrmPurchaseById(bpmCrmPurchaseEntity bpmCrmPurchase) {
		return updateById(bpmCrmPurchase);
	}

	/**
     * 根居ID获取对象
     */
    @DataSource(name="FLOWABLE")
	public bpmCrmPurchaseEntity getbpmCrmPurchaseById(String id){
		return getById(id);
	}
}
